package com.leyou.gateway.auth.feign;

import com.leyou.common.constants.LyConstants;
import com.leyou.gateway.auth.schedu.AppTokenScheduled;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.Period;

/**
 * User: ycs
 * Date: 2020/9/2
 * Time: 19:08
 * Description: Feign服务调用拦截器
 *
 * @author: ycs
 */
@Component
public class AuthFeignInterceptor implements RequestInterceptor {
    @Autowired
    private AppTokenScheduled appTokenScheduled;
    @Override
    public void apply(RequestTemplate requestTemplate) {
        //获取token
        String token = appTokenScheduled.getToken();
        //设置请求头添加token
        requestTemplate.header(LyConstants.APP_TOKEN_HEADER,token);
    }
}
